'abuphysicsstuntdouble.monkey by Belimoth
Strict
Import abu.abutime
Import abucomponent



Interface IPhysics
	Method Move:Void(x:Int, y:Int)
End



Class PhysicsComponent Extends EntityComponent<IPhysics> Implements IPhysics, IJuggleable

Private
	Global juggler := New Juggler<PhysicsComponent>

Public
	Method Active:Bool() Property Return True End
	
	Method Update:Void(timePassed:Int = 0)
		_displacementX += owner.VelocityComponent.xDisplacement
		_displacementY += owner.VelocityComponent.yDisplacement
		
		owner.PositionComponent.X += _displacementX
		owner.PositionComponent.Y += _displacementY
		
		_displacementX = 0
		_displacementY = 0
	End
	
	Method New()
		juggler.Add(Self)
	End
	
	Method Move:Void(x:Int, y:Int)			'just adds to displacement, Update() does the actual movement
		_displacementX += x
		_displacementY += y
	End

	Function _Update:Void(timePassed:Int)
		juggler.Juggle(timePassed)
	End
	
Private
	Field _displacementX:Int
	Field _displacementY:Int
End



Function UpdatePhysics:Void(timePassed:Int = -1)
	If timePassed = -1 Then timePassed = Tick()
	PhysicsComponent._Update(timePassed)
End